package csc.fresher.service;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import csc.fresher.dao.impl.DepositAccountDaoImpl;
import csc.fresher.dao.impl.DepositAccountTransactionDaoImpl;
import csc.fresher.dao.impl.SavingAccountDaoImpl;
import csc.fresher.entity.CustomerAccount;
import csc.fresher.entity.DepositTransaction;

@Service
public class InternetTransactionServiceImpl implements
		InternetTransactionService {

	@Autowired
	DepositAccountDaoImpl depositAccountDaoImpl;

	public DepositAccountDaoImpl getDepositAccountDaoImpl() {
		return depositAccountDaoImpl;
	}

	public void setDepositAccountDaoImpl(DepositAccountDaoImpl depositAccountDaoImpl) {
		this.depositAccountDaoImpl = depositAccountDaoImpl;
	}

	public DepositAccountTransactionDaoImpl getDepositAccountTransactionDaoImpl() {
		return depositAccountTransactionDaoImpl;
	}

	public void setDepositAccountTransactionDaoImpl(
			DepositAccountTransactionDaoImpl depositAccountTransactionDaoImpl) {
		this.depositAccountTransactionDaoImpl = depositAccountTransactionDaoImpl;
	}

	@Autowired
	DepositAccountTransactionDaoImpl depositAccountTransactionDaoImpl;

	@Override
	public ArrayList<Long> getAccountNumber(long customerID) {
		ArrayList<Long> result = new ArrayList<Long>();
		ArrayList<CustomerAccount> depositAcc = (ArrayList<CustomerAccount>) depositAccountDaoImpl
				.getAccountByCustomerID(customerID);
		for (int i = 0; i < depositAcc.size(); i++) {
			result.add(depositAcc.get(i).getAccountNumber());
		}
		return result;
	}

	public List<DepositTransaction> getTransaction(long accNumber, Date formDate,
			Date toDate, boolean isInternet, int offset, int rowReturn) {
		Timestamp fromStampTime = new Timestamp(formDate.getTime());
		Timestamp toStampTime = new Timestamp(toDate.getTime()+86399999);
		List<DepositTransaction> list = depositAccountTransactionDaoImpl
				.searchTransactionByDepositAccountIdInGivenPeriod(accNumber,
						fromStampTime, toStampTime,isInternet, offset, rowReturn);

		return list;
	}

	@Override
	public int getNumberOfTransaction(long accNumber, Date formDate,
			Date toDate, boolean isInternet) {
		Timestamp fromStampTime = new Timestamp(formDate.getTime());
		Timestamp toStampTime = new Timestamp(toDate.getTime()+86399999);
		return depositAccountTransactionDaoImpl.getNumberOfTransactionByDepositAccountIdInGivenPeriod(accNumber, fromStampTime, toStampTime,isInternet);
	}
	
}
